//
//  yunChunVCViewController.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/11/24.
//  Copyright © 2015年 szb. All rights reserved.
//

#import "yunChunVCViewController.h"
#import "addPicGroupVC.h"
#import "yunPicListVC.h"
#import "AccountTool.h"
#import "BPLoginViewController.h"

@interface yunChunVCViewController ()<UIWebViewDelegate>

@end

@implementation yunChunVCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseWebView.delegate = self;
    
    [self setUpNav];
    // Do any additional setup after loading the view.
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    
    // 打印异常
    self.context.exceptionHandler =
    ^(JSContext *context, JSValue *exceptionValue)
    {
        context.exception = exceptionValue;
        BPLog(@"%@", exceptionValue);
    };
    
    self.context[@"api"] = self;
}

- (void)setUpNav
{
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithButtonName:@"添加" withPic:@"buttonAdd" tatget:self action:@selector(addPicGroup)];
}

- (void)addPicGroup
{
    addPicGroupVC *groupPic = [[addPicGroupVC alloc] init];
    groupPic.title = @"云存储";
    groupPic.webName = @"newPhoto.html";
    groupPic.block = ^(NSString *method,NSDictionary *data){
        [self.context[method] callWithArguments:@[data]];
    };
    [self.navigationController pushViewController:groupPic animated:YES];
}

- (void)showCloudPicList
{
    yunPicListVC *listVC = [[yunPicListVC alloc] init];
    listVC.title = @"云相册";
    listVC.webName = @"cloudSave1.html";
    listVC.block = ^(){
        [self.context[@"backToHere"] callWithArguments:@[]];
    };
    [self.navigationController pushViewController:listVC animated:YES];
}

- (NSString *)getConfig:(NSString *)key
{
    return [AccountTool account].uid;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
